package com.example.spgl.mapper;

import com.example.spgl.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper {
    @Select("SELECT * FROM `product`")
    List<Product> list();
    @Insert("insert into product(name,content,price,description,imageUrl) values (#{name},#{content},#{price},#{description},#{imageUrl})")
    void add(Product product);
    @Delete("delete from product where id=#{id}")
    void delete(int id);

    @Select("select * from product limit #{curPage},#{pageSize}")
    List<Product> pageList(@Param("curPage") Integer curPage,@Param("pageSize") Integer pageSize);

    //获取记录总数 用于分页查询
    @Select("select count(*) from product")
    int getCount();

    //修改商品
    @Update("update product set name = #{name}, content = #{content}, price = #{price}, description = #{description},imageUrl = #{imageUrl} where id = #{id}")
    void update(Product product);
    //根据id查信息
    @Select("select * from product where id = #{id}")
    Product selectById(int id);

    //批量删除操作
   @Delete("delete from product where id in (${ids})")
    void deleteByIds(@Param("ids") String ids);
   //重置数据库，数据库所有记录删除后进行重置操作
    @Update("ALTER TABLE product AUTO_INCREMENT = 1")
    void reset();
}
